import java.util.Stack;

class MinStack {
    Stack<Integer> stack = new Stack<>();
    Stack<Integer> minStack = new Stack<>();

    public MinStack(Stack<Integer> stack, Stack<Integer> minStack) {
        this.stack = stack;
        this.minStack = minStack;
    }

    public void push(int val){
//        无论如何，都会进入普通栈
        stack.push(val);
//        min栈，就要看情况
        if (minStack.empty()){
            minStack.push(val);
        }else {
            int peekNum = minStack.peek();
            if (val <= peekNum){
                minStack.push(val);
            }
        }
    }

    public void pop(){
        int popNum = stack.pop();
//        要不要判断栈是否为空
//        不用！因为题目说明，总是在非空栈上进行
        if (popNum == minStack.peek()) {
            minStack.pop();
        }
    }

    public int top(){
        return stack.peek();
    }

    public int getMin(){
        return minStack.peek();
    }
}
